package edu.hubu.factory;

import edu.hubu.log.Logger;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

/**
 * @author moonlan
 * date 2021/3/30 上午9:14
 */
@SuppressWarnings(value = "unused")
public interface ILoggerFactory {

    Logger getLogger(Class<?> clazz);

    static ILoggerFactory getFactory(String properties) {
        Properties pro = new Properties();
        try {
            pro.load(ILoggerFactory.class.getClassLoader().getResourceAsStream(properties));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String property = pro.getProperty("log.className");
        try {
            Class<?> aClass = Class.forName(property);
            Object instance = aClass.getConstructor().newInstance();
            return (ILoggerFactory) instance;
        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

}
